package com.hmdp.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * Swagger2配置信息
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket webApiConfig(){

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
//                .globalOperationParameters(this.getParameterList());

    }

    /**
     * 添加head参数配置
     */
//    private List<Parameter> getParameterList() {
//        ParameterBuilder clientIdTicket = new ParameterBuilder();
//        List<Parameter> pars = new ArrayList<Parameter>();
//        clientIdTicket.name("Constant.TOKEN_HERDER_KEY").description("token令牌")
//                .modelRef(new ModelRef("string"))
//                .parameterType("header")
//                .required(false).build(); //设置false，表示clientId参数 非必填,可传可不传！
//        pars.add(clientIdTicket.build());
//        return pars;
//    }

    private ApiInfo webApiInfo(){

        return new ApiInfoBuilder()
                .title("黑马点评api文档")
                .description("本文档描述了黑马点评api文档")
                .version("1.0")
//                .contact(new Contact("Helen", "https://atguigu.com", "55317332@qq.com"))
                .build();
    }

}